package com.dumengwei.cms_20.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import com.dumengwei.cms_20.entity.Artical;
import com.dumengwei.cms_20.service.CateService;

@Controller
public class CateController {
	@Autowired
	private CateService cateService;
	@RequestMapping("list")
	public String list(){
		return "list";
	}
	@RequestMapping("toAddd")
	public String aatoAdd(Model model){
		model.addAttribute("artical", new Artical());
		return "add";
	}
	@RequestMapping("add")
	public String add(@Valid @ModelAttribute("artical")Artical artical,BindingResult result,MultipartFile file){
		if(result.hasErrors()){
			return "add";
		}
		cateService.add(artical);
		return "redirect:list";
	}
	
	@RequestMapping("sanji")
	public Object sanji(Integer cid){
		return cateService.sanji(cid);
	}
	
	
	public void a(){
		System.out.println("aaaaaaaa");
	}
	
}
